home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug231 / array.c < prev    next >
Text File  |  1987-06-17  |  2KB  |  66 lines

  1. /*
  2.     Little Smalltalk
  3.         Array creation
  4.  
  5.         timothy a. budd 10/84
  6.  
  7.     builds a new instance of class array.
  8.     called mostly by the driver to construct array constants.
  9. */
  10. /*
  11.     The source code for the Little Smalltalk System may be freely
  12.     copied provided that the source of all files is acknowledged
  13.     and that this condition is copied with each file.
  14.  
  15.     The Little Smalltalk System is distributed without responsibility
  16.     for the performance of the program and without any guarantee of
  17.     maintenance.
  18.  
  19.     All questions concerning Little Smalltalk should be addressed to:
  20.  
  21.         Professor Tim Budd
  22.         Department of Computer Science
  23.         Oregon State University
  24.         Corvallis, Oregon
  25.         97331
  26.         USA
  27. */
  28. # include <stdio.h>
  29. # include "object.h"
  30.  
  31. class *Array = (class *) 0;
  32. class *ArrayedCollection = (class *) 0;
  33.  
  34. extern object *o_nil, *o_empty, *o_acollection;
  35. extern int started;        /* gets set after reading std prelude */
  36.  
  37. /* new_iarray - internal form of new array */
  38. object *new_iarray(size)
  39. int size;
  40. {    object *new;
  41.  
  42.     if (size < 0) cant_happen(2);
  43.     new = new_obj(Array, size, 0);
  44.     if (! started) {
  45.         sassign(new->super_obj, o_acollection);
  46.         }
  47.     else if (ArrayedCollection)
  48.         sassign(new->super_obj, new_inst(ArrayedCollection));
  49.     return(new);
  50. }
  51.  
  52. /* new_array - create a new array */
  53. object *new_array(size, initial)
  54. int size, initial;
  55. {    int i;
  56.     object *new;
  57.  
  58.     if (size == 0) return(o_empty);
  59.     new = new_iarray(size);
  60.     if (initial) {
  61.         for (i = 0; i < size; i++)
  62.             sassign(new->inst_var[ i ], o_nil);
  63.         }
  64.     return(new);
  65. }
  66.